#include "dialogsaleseditor.h"
#include "ui_dialogsaleseditor.h"
#include <QMessageBox>
#include <QDebug>

DialogSalesEditor::DialogSalesEditor(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogSalesEditor)
{
    ui->setupUi(this);
    ui->tableView->setModel (new QStandardItemModel(this));
    ui->tableView->setAddAutomaticRow (false);
    ui->tableView->setSortingEnabled (true);
}

void DialogSalesEditor::setSellerModel(SellerModel *model)
{
    ui->tableView->setSellerModel (model);    
}

DialogSalesEditor::~DialogSalesEditor()
{
    delete ui;
}

void DialogSalesEditor::setPosFileName(const QString &fileName)
{
    ui->tableView->loadPosFile(fileName);
    ui->lineEdit->setText (fileName);
}

void DialogSalesEditor::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void DialogSalesEditor::on_buttonBox_accepted()
{
    if (QMessageBox::question (this,
                               trUtf8 ("Speichern"),
                               trUtf8 ("Soll die POS Datei gespeichert werden?"),
                               QMessageBox::Yes | QMessageBox::No,
                               QMessageBox::No)==QMessageBox::Yes)
    {
        qDebug() << "Save pos file";
        ui->tableView->savePosFile (ui->lineEdit->text ());
    }
}
